package com.boot.controller;

import com.boot.Vo.CategoryVo;
import com.boot.pojo.Category;
import com.boot.result.Result;
import com.boot.service.CategoryService;
import io.swagger.v3.oas.annotations.Operation;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("category")
public class CategoryController {
    @Autowired
    private CategoryService categoryService;

    @Operation(summary = "获取分类数据")
    @GetMapping("page")
    public Result getCategoryList(CategoryVo categoryVo) {
        return categoryService.queryCategoryList(categoryVo);
    }

    @Operation(summary = "添加分类")
    @PostMapping
    public Result addCategory(@RequestBody Category category) {
        return categoryService.addCategory(category);
    }

    @Operation(summary = "修改分类")
    @PutMapping
    public Result updateCategory(@RequestBody Category category) {
        return categoryService.updateCategory(category);
    }

    @Operation(summary = "启用/禁用分类")
    @PostMapping("status/{status}")
    public Result updateCategoryStatus(@PathVariable Integer status, Integer id) {
        return categoryService.updateCategoryStatus(status, id);
    }

    @Operation(summary = "删除分类")
    @DeleteMapping
    public Result deleteCategory(@RequestParam Integer id) {
        return categoryService.deleteCategory(id);
    }

    @Operation(summary = "根据类型获取分类")
    @GetMapping("list")
    public Result getCategoryByType(@RequestParam Integer type) {
        return categoryService.getCategoryByType(type);
    }


}
